<?php

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);

$ret = socket_bind($socket,"127.0.0.1",9999);

$ret = socket_listen($socket,4);

$count = 0;
while(1){
    if (($msgsock = socket_accept($socket))<0) {
        echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
        break;
    }else{
        $msg = "abc\n";
        socket_write($msgsock,$msg,strlen($msg));

        $buf = socket_read($msgsock, 8192); // 获得客户端的输入
        $talkback = "收到的信息:$buf\n";
        echo $talkback;
        if (++$count >= 5) {
            break;
        };
    }
    socket_close($msgsock);
}

socket_close($socket);